<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <base href="${pageContext.servletContext.contextPath}/">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="static/js/layui/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="static/css/layui/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>


<script src="static/js/layui/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: 'feeManagement',
            page:'true',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 20, title: 'ID', sort: true},
                {field: 'outTradeNo', width: 200, title: '交易流水号'},
                {field: 'tradeNo', width: 200, title: '收费单号', sort: true},
                {field: 'totalAmount', width: 100, title: '交易总金额'},
                {field: 'tradeDate', title: '交易时间', minWidth: 150},
                {field: 'tradeStatus', title: '交易状态', minWidth: 150,templet:'#setStatus'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            id: 'testReload',
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        type:'get',
                        url: 'delTrade?id='+data.id,
                        dataType: 'json',
                        success:function (data){
                            if (data.statusCode==200){
                                var index = layer.alert(data.message, {
                                    title: '删除信息'
                                }, function () {
                                    // 关闭弹出层
                                    layer.close(index);
                                    table.reload('testReload', {
                                        page: {
                                            curr: 1 //重新从第 1 页开始
                                        }
                                    });

                                });
                            }else if (data.statusCode==300){
                                layer.msg(json.message,2000);
                            }
                        }
                        }
                    );
                });
                return false;
            }
        });

    });
</script>

<script type="text/html" id="setStatus">
    <%--    按钮默认关--%>
    <input type="checkbox" name="close" id="{{d.tradeStatus}}"
           {{#  if(d.tradeStatus === 0){ }}
           {{#  } else { }}
           checked=""
           {{#  } }}
           lay-skin="switch" lay-text="交易成功|交易失败"  lay-filter="switchTest">
</script>

</body>
</html>
